package jp.co.piratealliance.pirateAllianceWeb.web.action.com;

import java.util.Map;

import com.opensymphony.xwork2.ActionContext;

import jp.co.piratealliance.pirateAllianceWeb.common.base.BaseAction;
import jp.co.piratealliance.pirateAllianceWeb.dto.com.UserInfoDto;
import jp.co.piratealliance.pirateAllianceWeb.service.com.UserService;

/**
 * copyright pirate alliance team 2014
 *
 * @author songyong
 */

public class LoginWebAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private UserService userService;

	private UserInfoDto userInfoDto;
	
	private String email;
	
	private String password;
    
	//private String  loginStatus;
	
	private String oldURL;


	public String getOldURL() {
		return oldURL;
	}
	public void setOldURL(String oldURL) {
		this.oldURL = oldURL;
	}
 
	public String userLogin()
	{   
		this.userInfoDto = this.userService.getUserInfo(this.email, this.password);
		if(this.userInfoDto!=null)
		{   
			Map<String, Object> session=ActionContext.getContext().getSession();
			session.put("user", this.userInfoDto);
        this.oldURL=(String)session.get("oldURL");

    	if(session.get("oldURL")!=null){
    		session.remove("oldURL");}

        if(this.oldURL!=null){
		return SUCCESS;}
        return "normalLogin";
		}
	//	this.loginStatus="1";
		this.addFieldError("loginerror", getText("message_loginError"));
	    return ERROR;
	}
	/**
	 * @return the userService
	 */
	public UserService getUserService() {
		return userService;
	}

	/**
	 * @param userService the userService to set
	 */
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	/**
	 * @return the userInfoDto
	 */
	public UserInfoDto getUserInfoDto() {
		return userInfoDto;
	}

	/**
	 * @param userInfoDto the userInfoDto to set
	 */
	public void setUserInfoDto(UserInfoDto userInfoDto) {
		this.userInfoDto = userInfoDto;
	}

	/**
	 * @return the email
	 */
	public String getEmail() {
		return email;
	}

	/**
	 * @param email the email to set
	 */
	public void setEmail(String email) {
		this.email = email;
	}

	/**
	 * @return the password
	 */
	public String getPassword() {
		return password;
	}

	/**
	 * @param password the password to set
	 */
	public void setPassword(String password) {
		this.password = password;
	}
	
	
}
